#ifndef DATABASE_H
#define DATABASE_H

#include <vector>
#include <utility/type.h>

namespace Zen{
namespace database_helper
{
	string sql_string(const char* fmt, ...);
}

class database
{
public:
	typedef std::vector<tstring> record_type;
	typedef std::vector<record_type> table_type;

public:
	database(){};
	virtual ~database(){};

	//stringT

	virtual bool open() = 0;

	virtual void close() = 0;

	virtual bool is_open() = 0;

	virtual bool get_table(const tstring& sql, table_type& table) = 0;

	virtual bool get_table(const tstring& sql, table_type& table, int& records) = 0;

	virtual bool execute(const tstring& sql) = 0;

	virtual bool begin_transaction() = 0;

	virtual bool commit_transaction() = 0;

	virtual bool exist_table(const tstring& table) = 0;

	virtual tstring get_error();

	virtual bool has_table( const tstring& dbname, const tstring& table );

public:
	void get_value(table_type& table, int row, int column, tstring& value);

	void get_value(table_type& table, int row, int column, int& value);

	void get_value(table_type& table, int row, int column, bool& value);

	void get_value(table_type& table, int row, int column, double& value);

protected:
	virtual std::string _get_coding_sql(const tstring& sql);

	virtual tstring _error_message() = 0;
	
protected:
	tstring error_;

};//end database

}//end Zen

#endif